home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / tnos / tnos100s / hma.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-13  |  1.2 KB  |  77 lines

  1. #include <dos.h>
  2. #include <errno.h>
  3. #include <alloc.h>
  4.  
  5. #define USEHMA 1
  6. #ifdef USEHMA
  7.  
  8. int weOwnHMA = 0;
  9. static short a20State = 0;
  10.  
  11. #ifdef    LARGEDATA
  12. #define    HUGE    huge
  13. #else
  14. #define    HUGE
  15. #endif
  16.  
  17. union header {
  18.     struct {
  19.         union header HUGE *ptr;
  20.         unsigned long size;
  21.     } s;
  22.     long l[2];
  23. };
  24.  
  25. typedef union header HEADER;
  26. #define    ABLKSIZE    (sizeof (HEADER))
  27. extern unsigned long Frees;    /* Total frees */
  28. extern unsigned long Heapsize;
  29.  
  30. int
  31. initHMA()
  32. {
  33. HEADER HUGE *up;
  34. unsigned nu;
  35.  
  36.     xms_init();
  37.     errno = 0;
  38.     xms_allocHMA (0xFFFF);
  39.     if (!errno)    {
  40.         weOwnHMA = 1;
  41.         up = (HEADER HUGE *) MK_FP (0xffff, 0x0010);
  42.         xms_getA20State (&a20State);
  43.         if (!a20State)
  44.             xms_globEnabA20();
  45.         nu = 65520 / ABLKSIZE;
  46.         up->s.size = nu;
  47.         up->s.ptr = up;    /* satisfy audit */
  48.         free((void *)(up + 1));
  49.         Heapsize += nu*ABLKSIZE;
  50.         Frees--;    /* Nullify increment inside free() */
  51.     }
  52.     return weOwnHMA;
  53. }
  54.  
  55.  
  56. void
  57. termHMA ()
  58. {
  59.     if (weOwnHMA)    {
  60.         if (!a20State)
  61.             xms_globDisabA20();    
  62.         xms_freeHMA ();
  63.     }
  64. }    
  65.  
  66.  
  67. void
  68. hmastat ()
  69. {
  70.     tprintf ("High Memory Area is %sowned by TNOS", weOwnHMA ? "" : "NOT ");
  71.     if (weOwnHMA)
  72.         tprintf (" - Extra 64K in use");
  73.     tputc ('\n');
  74. }
  75. #endif
  76.  
  77.